<title>用户管理</title>
  
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>问答管理</cite></a>
    <a><cite>用户</cite></a>
    <a><cite>用户管理</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-card">
    <form class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="J_ajaxForm">
      <div class="layui-form-item">
        <div class="layui-inline">
          <label class="layui-form-label">UID</label>
          <div class="layui-input-block" style="width: 100px;">
            <input type="text" name="uid" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-block">
            <input type="text" name="username" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">邮箱</label>
          <div class="layui-input-block">
            <input type="text" name="email" autocomplete="off" class="layui-input">
          </div>
        </div>

        <div class="layui-inline">
          <label class="layui-form-label">用户组</label>
          <div class="layui-input-block">
              <select class="layui-select" name="group">
                <option value="0">全部</option>
                {volist name="group" id="item"}
                <option value="{$item.id}">{$item.name}</option>
                {/volist}
              </select>
          </div>
        </div>

        <div class="layui-inline">
          <label class="layui-form-label">状态</label>
          <div class="layui-input-block">
              <select class="layui-select" name="status">
                <option value="">全部</option>
                <option value="1">正常</option>
                <option value="0">待审核</option>
              </select>
          </div>
        </div>
        
        <div class="layui-inline">
          <button class="layui-btn" lay-submit lay-filter="J_form_search">搜索</button>
        </div>
      </div>
    </form>
    
    <div class="layui-card-body">
      <div style="padding-bottom: 10px;">
        <a href="#J_view" class="layui-btn J_popup" title="添加用户"><i class="layui-icon layui-icon-add-circle"></i>添加</a>
        <a href="wendasns/user/remove" class="layui-btn J_req" title="确定删除吗？"><i class="layui-icon layui-icon-delete"></i>删除</a>
        <a href="#J_batch" class="layui-btn J_popup" title="批量操作"><i class="layui-icon layui-icon-ok"></i>批量操作</a>
      </div>
      
      <table id="J_table_list" lay-filter="J_table_list"></table>

    </div>
  </div>
</div>

<script type="text/html" id="J_templet_group">
  {volist name="group" id="item"}
    {{# if(d.group_id=={$item.id}){ }}{$item.name}{{# } }}
  {/volist}
</script>

<script type="text/html" id="J_templet_status">
  {{# if(d.status==1){ }}
  <span style="color: #5FB878;">正常</span>
  {{# }else{ }}
  <span style="color: #FFB800;">待审核</span>
  {{# } }}
</script>

<script type="text/html" id="J_table_tool">
  <a href="wendasns/user/edit" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="popup" title="编辑用户"><i class="layui-icon layui-icon-edit"></i>编辑</a>
  <a href="wendasns/user/remove" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="req" title="确定删除吗？"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<script>
;!function(){
  var $ = layui.$
  ,admin = layui.admin
  ,form = layui.form
  ,table = layui.table;

  form.render();

  //执行渲染
table.render({
  elem: '#J_table_list'
  ,url: '{:url('wendasns/user/list')}'
  ,cols: [[
      {type: 'checkbox'}
      ,{field:'id',title:'UID',width:80,align:'center',sort: true}
      ,{field:'group_id',title:'用户组',width:100,align:'center',templet:'#J_templet_group'}
      ,{field:'username',title:'用户名',minWidth:150}
      ,{field:'email',title:'邮箱',minWidth:200}
      ,{field:'mobile',title:'手机号',minWidth:170}
      ,{field:'create_time',title:'注册时间',width:200}
      ,{field:'status',title:'状态',align:'center',width:80,templet:'#J_templet_status'}
      ,{title:'操作',width:150,align:'center',toolbar:'#J_table_tool'}
  ]]
  ,page: true
    ,limit: 20
    ,height: 'auto'
  ,text: {
    none: '暂无数据！'
  }
});


    form.on('submit(J_ajaxSubmit)', function(obj){
    	var _form = $(obj.form),action = _form.prop('action'),method = _form.prop('method');

		var data = table.checkStatus('J_table_list'),post = [];
  	  	$.each(data.data,function(){
  	  		post.push(this.id);
        });
		if(post.length === 0){
			layer.msg('\u8bf7\u9009\u62e9\u6570\u636e');
			return false;
		}
        obj.field.id = post;
        admin.req({
           url: action
           ,type: method
           ,dataType: 'html'
           ,data: obj.field
           ,done: function(res){
               layer.msg(res.msg, {time:1000}, function(){
    				admin.events.refresh();
    		   });
           }
           ,error: function(res){
    			layer.msg(res.msg);
    		}
        });
        return false;
    });
    
    
}();
</script>

<script type="text/html" id="J_view">
<form class="layui-form" action="{:url('wendasns/user/add')}" method="post">

            <div class="layui-form-item">
              <label class="layui-form-label">用户名</label>
              <div class="layui-input-inline">
                <input type="text" name="username" value="" lay-verify="required" class="layui-input">
              </div>
            </div>
            
            <div class="layui-form-item">
              <label class="layui-form-label">密码</label>
              <div class="layui-input-inline">
                <input type="password" name="password" value="" lay-verify="required" class="layui-input">
              </div>
            </div>
 
             <div class="layui-form-item">
              <label class="layui-form-label">邮箱</label>
              <div class="layui-input-inline">
                <input type="text" name="email" value="" lay-verify="email" class="layui-input">
              </div>
            </div>

             <div class="layui-form-item">
              <label class="layui-form-label">手机号</label>
              <div class="layui-input-inline">
                <input type="text" name="mobile" value="" lay-verify="phone" class="layui-input">
              </div>
            </div>
            
            <div class="layui-form-item">
            <label class="layui-form-label">用户组</label>
            <div class="layui-input-inline">
              <select class="layui-select" name="group">
                {volist name="group" id="item"}
                <option value="{$item.id}">{$item.name}</option>
                {/volist}
              </select>
            </div>
          </div>
            
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="J_ajax_submit_btn"><i class="layui-icon layui-icon-ok-circle"></i>提交</button>
              </div>
            </div>
            
          </form>
</script>

<script type="text/html" id="J_batch">
<form class="layui-form" action="{:url('wendasns/user/check')}" method="post">

            <div class="layui-form-item">
            <label class="layui-form-label">用户组</label>
            <div class="layui-input-inline">
              <select class="layui-select" name="group">
                <option value="">请选择</option>
                {volist name="group" id="item"}
                <option value="{$item.id}">{$item.name}</option>
                {/volist}
              </select>
            </div>
          </div>

            <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
              <select class="layui-select" name="status">
                <option value="">请选择</option>
                <option value="1">正常</option>
                <option value="0">待审核</option>
              </select>
            </div>
          </div>
          
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="J_ajaxSubmit"><i class="layui-icon layui-icon-ok-circle"></i>确定</button>
              </div>
            </div>
            
          </form>
</script>